package 热题100;

import java.util.ArrayList;
import java.util.List;

public class 热题48全排列 {

    int[] nums;
    public List<List<Integer>> permute(int[] nums) {
        this.nums = nums;
        List<List<Integer>> lists = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        dfs(-1,lists,list);
        return lists;
    }
    public void dfs(int index,List<List<Integer>> lists, List<Integer> path ){
        //如果路径等于当前数组长度
        if (path.size() == nums.length){
            ArrayList<Integer> list = new ArrayList<>(path);
            lists.add(list);
            //剪枝
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (path.contains(nums[i])) continue;
            path.add(nums[i]);
            dfs(i,lists,path);
            path.remove(path.size()-1);
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        System.out.println(new 热题48全排列().permute(arr));
    }
}
